package com.ruoyi.web.controller.sports;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sports.domain.vo.EventVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sports.domain.Event;
import com.ruoyi.sports.service.IEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 赛事项目Controller
 * 
 * @author ZJH
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/sports/event")
public class EventController extends BaseController
{
    @Autowired
    private IEventService eventService;

    /**
     * 查询赛事项目列表
     */
    @PreAuthorize("@ss.hasPermi('sports:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(Event event)
    {
        startPage();
        List<EventVO> list = eventService.selectEventList(event);
        return getDataTable(list);
    }

    /**
     * 导出赛事项目列表
     */
    @PreAuthorize("@ss.hasPermi('sports:event:export')")
    @Log(title = "赛事项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Event event)
    {
        List<EventVO> list = eventService.selectEventList(event);
        ExcelUtil<EventVO> util = new ExcelUtil<EventVO>(EventVO.class);
        util.exportExcel(response, list, "赛事项目数据");
    }

    /**
     * 获取赛事项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('sports:event:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return success(eventService.selectEventByEventId(eventId));
    }

    /**
     * 新增赛事项目
     */
    @PreAuthorize("@ss.hasPermi('sports:event:add')")
    @Log(title = "赛事项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Event event)
    {
        return toAjax(eventService.insertEvent(event));
    }

    /**
     * 修改赛事项目
     */
    @PreAuthorize("@ss.hasPermi('sports:event:edit')")
    @Log(title = "赛事项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Event event)
    {
        return toAjax(eventService.updateEvent(event));
    }

    /**
     * 删除赛事项目
     */
    @PreAuthorize("@ss.hasPermi('sports:event:remove')")
    @Log(title = "赛事项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(eventService.deleteEventByEventIds(eventIds));
    }
}
